package com.lottery.im.module.chat.presenter;

import android.app.Activity;
import com.lottery.im.base.BaseActivityPresenter;
import com.lottery.im.module.chat.view.SelectBusinessCardView;
import com.tencent.imsdk.TIMFriendshipManager;
import com.tencent.imsdk.TIMGroupMemberInfo;
import com.tencent.imsdk.TIMUserProfile;
import com.tencent.imsdk.TIMValueCallBack;
import com.tencent.imsdk.ext.group.TIMGroupManagerExt;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import java.util.List;

public class SelectBusinessCardPresenter extends BaseActivityPresenter<SelectBusinessCardView> {

  public SelectBusinessCardPresenter(Activity activity,
      SelectBusinessCardView iView,
      LifecycleProvider<ActivityEvent> provider) {
    super(activity, iView, provider);
  }

  public void getGroupMembers(String dentify) {
    TIMGroupManagerExt.getInstance().getGroupMembers(dentify,
        new TIMValueCallBack<List<TIMGroupMemberInfo>>() {
          @Override public void onError(int i, String s) {
            if (null == iView) return;
            iView.showToast("获取群成员失败，请稍后再试～");
          }

          @Override public void onSuccess(List<TIMGroupMemberInfo> timGroupMemberInfos) {
            if (null == iView) return;
            iView.showMemberInfo(timGroupMemberInfos);
          }
        });
  }

  public void getUsersProfile(List<String> ids) {
    TIMFriendshipManager.getInstance().getUsersProfile(ids,
        new TIMValueCallBack<List<TIMUserProfile>>() {
          @Override public void onError(int i, String s) {

          }

          @Override public void onSuccess(List<TIMUserProfile> timUserProfiles) {
            if (null == iView) return;
            iView.refreshUsersProfile(timUserProfiles);
          }
        });
  }
}
